package com.lvtongka.app.fragment.common

import android.content.Context
import android.view.View
import com.lvtongka.app.R
import com.lvtongka.app.dialog.DialogSureCancel
import com.zw.pass.dialog.PayPassDialog
import com.zw.pass.dialog.PayPassView

class DialogHelper {
    companion object {
        // 权限提示
        fun showPermissionHintDialog(context: Context, title: String, msg: String, sureListener: View.OnClickListener?) {
            val sureCancel = DialogSureCancel(context)
            sureCancel.setTitle(title)
            sureCancel.setContent(msg)
            sureCancel.setCancelable(false)
            sureCancel.setCanceledOnTouchOutside(false)
            sureCancel.setSure("去设置")
            sureCancel.setSureListener {
                sureCancel.cancel()
                sureListener?.onClick(null)
            }
            sureCancel.setCancelListener {
                sureCancel.cancel()
            }
            sureCancel.show()
        }

        // 绑券提示
        fun showBindQuanHintDialog(context: Context, balance: String, name: String, sureListener: View.OnClickListener?) {
            val sureCancel = DialogSureCancel(context)
            sureCancel.setTitle("绑券")
            sureCancel.setContent("是否绑定此张面值为【$balance】的【$name】?")
            sureCancel.setCancelable(false)
            sureCancel.setCanceledOnTouchOutside(false)
            sureCancel.setSure("确认绑定")
            sureCancel.setSureListener {
                sureCancel.cancel()
                sureListener?.onClick(null)
            }
            sureCancel.setCancelListener {
                sureCancel.cancel()
            }
            sureCancel.show()
        }

        // 绑卡提示
        fun showBindCardHintDialog(context: Context, cardNo: String, balance: String, sureListener: View.OnClickListener?) {
            val sureCancel = DialogSureCancel(context)
            sureCancel.setTitle(cardNo + "卡内余额:\n" + balance + "元，请确认是否绑定")
            sureCancel.setContent("绑定后实体卡片仍可至线下商户\n进行刷卡，请勿丢弃")
            sureCancel.setCancelable(false)
            sureCancel.setCanceledOnTouchOutside(false)
            sureCancel.setSure("确认绑定")
            sureCancel.setSureListener {
                sureCancel.cancel()
                sureListener?.onClick(null)
            }
            sureCancel.setCancelListener {
                sureCancel.cancel()
            }
            sureCancel.show()
        }

        // 实名认证提示
        fun showPhoneHintDialog(context: Context, sureListener: View.OnClickListener?) {
            val sureCancel = DialogSureCancel(context)
            sureCancel.setTitle("联系客服")
            sureCancel.setContent("客服电话：0519-85605725 服务时间：9:00-17:00，感谢您的支持与监督")
            sureCancel.setCancelable(false)
            sureCancel.setCanceledOnTouchOutside(false)
            sureCancel.setSure("立即拨打")
            sureCancel.setSureListener {
                sureCancel.cancel()
                sureListener?.onClick(null)
            }
            sureCancel.setCancelListener {
                sureCancel.cancel()
            }
            sureCancel.show()
        }

        // 实名认证提示
        fun showRealNameHintDialog(context: Context, sureListener: View.OnClickListener?) {
            val sureCancel = DialogSureCancel(context)
            sureCancel.setTitle("提示")
            sureCancel.setContent("用户尚未实名认证，请先实名认证")
            sureCancel.setCancelable(false)
            sureCancel.setCanceledOnTouchOutside(false)
            sureCancel.setSureListener {
                sureCancel.cancel()
                // 实名弹窗
                sureListener?.onClick(null)
            }
            sureCancel.setCancelListener {
                sureCancel.cancel()
            }
            sureCancel.show()
        }

        // 开启扫码支付
        fun showScanPayDialog(context: Context, sureListener: View.OnClickListener?) {
            val sureCancel = DialogSureCancel(context)
            sureCancel.setTitle("开启扫码支付")
            sureCancel.setContent("用户尚未开通扫码支付，是否开通扫码支付")
            sureCancel.setCancelable(false)
            sureCancel.setCanceledOnTouchOutside(false)
            sureCancel.setSureListener {
                // 开启扫码支付
                sureCancel.cancel()
                sureListener?.onClick(null)
            }
            sureCancel.setCancelListener {
                sureCancel.cancel()
            }
            sureCancel.show()
        }

        // 设置支付密码弹窗
        fun showPayHintDialog(context: Context, sureListener: View.OnClickListener?) {
            val sureCancel = DialogSureCancel(context)
            sureCancel.setTitle("提示")
            sureCancel.setContent("用户尚未设置支付密码，请设置支付密码")
            sureCancel.setCancelable(false)
            sureCancel.setCanceledOnTouchOutside(false)
            sureCancel.setSureListener {
                sureCancel.dismiss()
                sureListener?.onClick(null)
            }
            sureCancel.setCancelListener {
                sureCancel.dismiss()
            }
            sureCancel.show()
        }

        // 设置支付密码弹窗 第一次弹窗
        fun showSetPayFirstDialog(context: Context, pyCallback: SetPayCallback) {
            val dialog = PayPassDialog(context)
            dialog.payViewPass.setTitleText("设置支付密码")
            dialog.payViewPass.setHintText("为了保障账户安全，请设置旅通支付密码")
            dialog.payViewPass.setForgetText("")
            dialog.payViewPass
                .setRandomNumber(true).setPayClickListener(object : PayPassView.OnPayClickListener {

                    override fun onPassFinish(password: String?) {
                        pyCallback.onSetPayResult(password!!)
                        dialog.dismiss()
                    }

                    override fun onPayClose() {
                        dialog.dismiss()
                        //关闭弹框
                    }

                    override fun onPayForget() {
                        dialog.dismiss()
                        //点击忘记密码回调
                    }
                })
        }

        // 设置支付密码弹窗 第二次弹窗
        fun showSetPaySecondDialog(context: Context, pyCallback: SetPayCallback) : PayPassDialog {
            val dialog = PayPassDialog(context)
            dialog.payViewPass.setTitleText("设置支付密码")
            dialog.payViewPass.setHintText("请再次输入")
            dialog.payViewPass.setForgetText("")
            dialog.payViewPass
                .setRandomNumber(true).setPayClickListener(object : PayPassView.OnPayClickListener {

                    override fun onPassFinish(password: String?) {
                        pyCallback.onSetPayResult(password!!)
                    }

                    override fun onPayClose() {
                        dialog.dismiss()
                        //关闭弹框
                    }

                    override fun onPayForget() {
                        dialog.dismiss()
                        //点击忘记密码回调
                    }
                })
            return dialog
        }

        // 解绑确认弹窗
        fun showConfirmHintDialog(context: Context, sureListener: View.OnClickListener?) {
            val sureCancel = DialogSureCancel(context)
            sureCancel.setTitle("提示")
            sureCancel.setContent("确定解绑吗？")
            sureCancel.setCancelable(false)
            sureCancel.setCanceledOnTouchOutside(false)
            sureCancel.setSureListener {
                sureCancel.cancel()
                // 确定
                sureListener?.onClick(null)
            }
            sureCancel.setCancelListener {
                sureCancel.cancel()
            }
            sureCancel.show()
        }

        // 弹出支付弹窗 输入支付密码
        fun showPayPwdDialog(context: Context, name: String, balance: String, pyCallback: PasswordCallback) {
            val dialog = PayPassDialog(context)
            dialog.payViewPass.setTitleText("请输入支付密码")
            dialog.payViewPass.setStoreNameText(name)
            dialog.payViewPass.setBalanceText(balance)
//            dialog.payViewPass.setForgetText("太麻烦？开通小额免密支付")
            dialog.payViewPass
                .setRandomNumber(true).setPayClickListener(object : PayPassView.OnPayClickListener {

                    override fun onPassFinish(password: String?) {
                        pyCallback.onPasswordResult(password!!)
                        dialog.dismiss()
                    }

                    override fun onPayClose() {
                        dialog.dismiss()
                        //关闭弹框
                    }

                    override fun onPayForget() {
                        dialog.dismiss()
                        //点击忘记密码回调
                        pyCallback.onSecretFree()
                    }
                })
        }

        // 弹出支付弹窗 输入支付密码
        fun showPayPwdDialog(context: Context, pyCallback: SetPayCallback) {
            val dialog = PayPassDialog(context)
            dialog.payViewPass.setTitleText("请输入支付密码")
            dialog.payViewPass
                .setRandomNumber(true).setPayClickListener(object : PayPassView.OnPayClickListener {

                    override fun onPassFinish(password: String?) {
                        pyCallback.onSetPayResult(password!!)
                        dialog.dismiss()
                    }

                    override fun onPayClose() {
                        dialog.dismiss()
                    }

                    override fun onPayForget() {
                        dialog.dismiss()
                    }
                })
        }
    }
}